<template>
	<view class="index">
		<view class="top">
			<view class="search">
				<image src="@/static/index/ss.png" mode=""></image>
				<input type="text" placeholder="搜索商品" placeholder-style="color:#fff"
					@click="toPage('./goods-search')" />
			</view>
		</view>
		<!-- 轮播图 -->
		<view class="swiper">
			<swiper :indicator-dots="true" circular="true" indicator-color="#fff" indicator-active-color="#ccc"
				:autoplay="true" :interval="3000" :duration="1000">
				<swiper-item v-for="(item,index) in banner" :key="index">
					<view class="swiper-item">
						<image :src="item.file_path" mode=""></image>
						<!-- <image src="/static/index/banner22.png" mode=""></image> -->
					</view>
				</swiper-item>
			</swiper>
		</view>
		<!-- 导航栏 -->
		<view class="nav">
			<view class="nav-tab" @click="toPage('/pages/classlist/index')">
				<image src="../../static/index/tab1.png" mode=""></image>
				<text>商品分类</text>
			</view>
			<view class="nav-tab" @click="toPage('/pages/cart/index')">
				<image src="../../static/index/tab2.png" mode=""></image>
				<text>购物车</text>
			</view>
			<view class="nav-tab" @click="toPage('/pages/index/goods-system')">
				<image src="../../static/index/tab3.png" mode=""></image>
				<text>无限娱乐</text>
			</view>
			<!-- <view class="nav-tab" @click="toPage('/pages/index/goods-store')">
				<image src="../../static/index/tab4.png" mode=""></image>
				<text>商家自营</text>
			</view> -->
			<view class="nav-tab" @click="toPage('/pages/order/index')">
				<image src="../../static/index/tab5.png" mode=""></image>
				<text>我的订单</text>
			</view>
		</view>
		<!-- 专区 -->
		<view class="hot">
			<view class="title">
				<text class="name">热门专区</text>
			</view>
			<view class="goods">
				<view class="goodsitem" v-for="(item,index) in goods" :key='item.id'
					@click="toPage('/pages/goodsdetail/index?id='+item.id)">
					<image :src="item.cover_path" mode=""></image>
					<text class="name">{{item.name}}</text>
					<!-- <text class="des">{{item.sketch}}</text> -->
					<view class="price">
						<view>
							￥<text class="pricenum">{{item.price}}</text>
						</view>
						<view class="sell">
							已售:{{item.total_sales}}
						</view>
					</view>
				</view>
				<view class="no-list" v-if="goods.length == 0">
					- 暂无数据 -
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		Home,
		hotGoods
	} from '@/api/api.js'
	export default {
		data() {
			return {
				goods: [],
				banner: [],
				conf: [],
				last_page: 1,
				page: 1
			}
		},
		onLoad() {
			this.IndexGoods()
			this.hotGoods()
		},
		onReachBottom() {
			if (this.page < this.last_page) {
				this.page++
				this.hotGoods
			}
		},
		methods: {
			hotGoods() {
				hotGoods({
					page: this.page
				}).then(res => {
					if (res.code == 0) {
						this.goods = this.goods.concat(res.data.data)
						this.last_page = res.data.last_page
					}
				})
			},
			IndexGoods() {
				Home().then(res => {
					if (res.code == 0) {
						this.banner = res.data.banner
						this.conf = res.data.conf
					}
				})
			},
			totwPage(url) {
				uni.switchTab({
					url
				})
			},
			toPage(url) {
				uni.navigateTo({
					url: url
				})
			},
			toTarPage(url) {
				uni.switchTab({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss">
	.top {
		background: $uni-bg-color;
		padding-bottom: 100px;
		padding-top: 20px;

		.news {
			text-align: right;
			padding-right: 5%;
			position: fixed;
			top: 8px;
			z-index: 99999;
			right: 2%;

			image {
				width: 50rpx;
				height: 50rpx;
			}
		}

		.logo {
			display: flex;
			justify-content: center;
			padding-bottom: 30rpx;
			padding-top: 20rpx;

			image {
				width: 60%;
				height: 90px;
			}
		}

		.search {
			position: relative;
			width: 90%;
			background: #ffffff4d;
			border-radius: 20px;
			margin: 00px auto;
			display: flex;
			align-items: center;
			padding: 0 10px;
			box-sizing: border-box;
			padding-left: 20px;

			image {
				width: 20px;
				height: 20px;
			}

			input {
				width: 80%;
				margin-left: 10px;
				line-height: 40px;
				height: 40px;
				color: #fff;
			}


		}

	}

	.swiper {
		margin-top: -80px;
		height: 160px;
		border-radius: 10px;

		swiper {
			height: 160px;
		}

		.swiper-item {
			text-align: center;

			image {
				width: 96%;
				margin: 0 auto;
				height: 160px;
				border-radius: 5px;
			}
		}
	}

	.nav {
		display: flex;
		justify-content: space-around;
		width: 90%;
		margin: 0 auto;
		margin-top: 10px;

		.nav-tab {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			image {
				width: 45px;
				height: 45px;
			}

			text {
				font-size: 13px;
				color: #666;
			}
		}
	}

	.hot {
		margin-top: 25px;

		.title {
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 90%;
			margin: 0 auto;
			border-left: 4px solid $uni-bg-color;
			padding-left: 2%;
			margin-bottom: 10px;

			.name {
				color: $uni-bg-color;
				font-size: 15px;
				font-weight: bold;
			}

			.more {
				font-size: 12px;
				color: #999999;
			}
		}

		.goods {
			display: table;
			width: 100%;
			background: #F7F7F7;

			.goodsitem {
				display: flex;
				flex-direction: column;
				width: 45%;
				float: left;
				margin: 20rpx 2.5%;
				background: #fff;
				border-radius: 5px;


				image {
					width: 100%;
					height: 180px;
					border-radius: 5px;
				}

				.name {
					font-size: 15px;
					width: 100%;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					font-weight: bold;
					padding: 5px;
				}

				.des {
					padding: 0 5px;

					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
					overflow: hidden;
					font-size: 12px;
					color: #777;
				}

				.price {
					color: #C79E76;
					font-size: 14px;
					padding: 5px;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.pricenum {
						font-size: 18px;
						font-weight: bold;
					}

					.sell {
						font-size: 12px;
					}
				}

				.vipprice {
					font-size: 14px;
				}
			}
		}
	}
</style>